<?php 
class Application_Model_Navigation extends Application_Model_DomainObject
{
    protected $_id;
    protected $_parentId;
    protected $_name;
    protected $_url;
    protected $_type;
    protected $_order;
    protected $_operator;
    protected $_status;
    protected $_dateCreated;
    protected $_sign;
    protected $_isNum;//是够后面显示数据 1显示 0 不显示
    /**
     * 头部导航
     */
    const Type_Top = 1;
    /**
     * 左边导航
     */
    const Type_Left = 2;
    /**
     * 禁用
     */
    const Status_Disable = 0;
    /**
     * 可用
     */
    const Status_Launch = 1;
    
    public static function addOrEditNavigation($parentId,$id,$name,$url,$type,$sign,$order,$status,$isNum)
    {
        if($id != ""){
            $navigationItem = Application_Model_Navigation::load($id);
            if(!$navigationItem){
                Application_Model_Operate::addOperate(0, null, 0, "添加后台导航：" . $name, 0);
                $navigationItem = new Application_Model_Navigation();
                $navigationItem->DateCreated = date("Y-m-d H:i:s");
                $navigationItem->Operator = Uuch_Util::getUserNikeName();
            } else {
                Application_Model_Operate::addOperate(0, null, 0, "修改后台导航：" . $name, 0);
            }
        }else{
            Application_Model_Operate::addOperate(0, null, 0, "添加后台导航：" . $name, 0);
            $navigationItem = new Application_Model_Navigation();
            $navigationItem->DateCreated = date("Y-m-d H:i:s");
            $navigationItem->Operator = Uuch_Util::getUserNikeName();
        }
        $navigationItem->ParentId = $parentId;
        $navigationItem->Name = $name;
        $navigationItem->Url = $url;
        $navigationItem->Type = $type;
        $navigationItem->Sign = $sign;
        $navigationItem->Order = $order;
        $navigationItem->Status = $status;
        $navigationItem->isNum = $isNum; 
        $navigationItem->save();
        return $navigationItem->Id;
    }
    
    public static function getNavigationFileds($parentId,$pagesize,$pageindex)
    {
        return self::getDao()->queryPage(array("parentId = "=>$parentId), " order asc ", $pagesize, $pageindex);
    }
    
    public static function getTypeAll()
    {
        return array(
                   self::Type_Top => "头部导航"
                ,  self::Type_Left => "左边导航"
        );
    }

    public function getTypeName()
    {
        $arrType = self::getTypeAll();
        return $arrType[$this->_type];
    }
     
    public static function getStatusAll()
    {
        return array(
                   self::Status_Launch => "启用"
                ,  self::Status_Disable => "禁用"
        );
    }
    
    public function getStatusName()
    {
        $arrStatus = self::getStatusAll();
        return $arrStatus[$this->_status];
    }
    
    public static function getAllByParentId($parentId)
    {
        return self::getDao()->queryAll(array("parentId"=>$parentId)," order asc ");
    }
    
    public static function getAllByTypeParentId($type,$parentId,$status)
    {
//        echo 123;exit;
        return self::getDao()->queryAll(array("type"=>$type," and parentId = "=>$parentId," and status = "=>$status), " order asc ");
    }
    
    public function getParentNavigationByParentIdTypeStatus($type,$status)
    {
        return self::getDao()->queryAll(array(" parentId = "=>  $this->_id," and status = "=>$status," and type = "=>$type), " order asc ");
    }
}
